package com.dianping.cat.home.heartbeat.transform;

import com.dianping.cat.home.heartbeat.entity.Group;
import com.dianping.cat.home.heartbeat.entity.HeartbeatDisplayPolicy;
import com.dianping.cat.home.heartbeat.entity.Metric;
import org.xml.sax.Attributes;









public class DefaultSaxMaker
  extends Object
  implements IMaker<Attributes>
{
  public Group buildGroup(Attributes attributes) {
/*  21 */     String id = attributes.getValue("id");
/*  22 */     String order = attributes.getValue("order");
/*  23 */     Group group = new Group(id);

    if (order != null) {
/*  26 */       group.setOrder(((Integer)convert(Integer.class, order, Integer.valueOf(0))).intValue());
    }

    return group;
  }



/*  34 */   public HeartbeatDisplayPolicy buildHeartbeatDisplayPolicy(Attributes attributes) { return new HeartbeatDisplayPolicy(); }





  public Metric buildMetric(Attributes attributes) {
/*  41 */     String id = attributes.getValue("id");
/*  42 */     String unit = attributes.getValue("unit");
/*  43 */     String delta = attributes.getValue("delta");
/*  44 */     String order = attributes.getValue("order");
/*  45 */     String title = attributes.getValue("title");
/*  46 */     String lable = attributes.getValue("lable");
/*  47 */     String alert = attributes.getValue("alert");
/*  48 */     Metric metric = new Metric(id);

/*  50 */     if (unit != null) {
/*  51 */       metric.setUnit(unit);
    }

/*  54 */     if (delta != null) {
/*  55 */       metric.setDelta(((Boolean)convert(Boolean.class, delta, Boolean.valueOf(false))).booleanValue());
    }

/*  58 */     if (order != null) {
/*  59 */       metric.setOrder(((Integer)convert(Integer.class, order, Integer.valueOf(0))).intValue());
    }

/*  62 */     if (title != null) {
/*  63 */       metric.setTitle(title);
    }

/*  66 */     if (lable != null) {
/*  67 */       metric.setLable(lable);
    }

/*  70 */     if (alert != null) {
/*  71 */       metric.setAlert(((Boolean)convert(Boolean.class, alert, Boolean.valueOf(false))).booleanValue());
    }

/*  74 */     return metric;
  }


  protected <T> T convert(Class<T> type, String value, T defaultValue) {
/*  79 */     if (value == null || value.length() == 0) {
/*  80 */       return defaultValue;
    }

/*  83 */     if (type == Boolean.class || type == boolean.class)
/*  84 */       return (T)Boolean.valueOf(value); 
/*  85 */     if (type == Integer.class || type == int.class)
/*  86 */       return (T)Integer.valueOf(value); 
/*  87 */     if (type == Long.class || type == long.class)
/*  88 */       return (T)Long.valueOf(value); 
/*  89 */     if (type == Short.class || type == short.class)
/*  90 */       return (T)Short.valueOf(value); 
/*  91 */     if (type == Float.class || type == float.class)
/*  92 */       return (T)Float.valueOf(value); 
/*  93 */     if (type == Double.class || type == double.class)
/*  94 */       return (T)Double.valueOf(value); 
    if (type == Byte.class || type == byte.class)
/*  96 */       return (T)Byte.valueOf(value); 
/*  97 */     if (type == Character.class || type == char.class) {
/*  98 */       return (T)Character.valueOf(value.charAt(0));
    }
/* 100 */     return (T)value;
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/heartbeat/transform/DefaultSaxMaker.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */